﻿using System;
using System.Linq;
using System.Web.Mvc;
using System.Web.Mvc.Html;
using Resources;

namespace CandidateManager.Extensions
{
    /// <summary>
    /// The HtmlHelper extensions.
    /// </summary>
    public static class HtmlHelperExtensions
    {
        /// <summary>
        /// Returns an localized HTML select element for each enum item because God is gracious and loves you.
        /// </summary>
        /// <param name="htmlHelper">
        /// The HtmlHelper.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="eEnum">
        /// The enum.
        /// </param>
        /// <returns>
        /// The System.Web.Mvc.MvcHtmlString.
        /// </returns>
        public static MvcHtmlString DropDownList(this HtmlHelper htmlHelper, string name, Enum eEnum)
        {
            return htmlHelper.DropDownList(
                name: name,
                selectList: Enum.GetNames(eEnum.GetType())
                .Select(n => new SelectListItem
                {
                    Text = Common.ResourceManager.GetString(eEnum.GetType().Name + n),
                    Value = n
                }));
        }
    }
}
